<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>接口文档自测</title>
    <link rel="stylesheet" href="demo.css">
    <meta name="viewport" content="width=device-width"> 
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://www.dowebok.com/demo/2013/5/js/jquery.collapse.js"></script>
  </head>
  <body>
    
    <h1>接口文档自测</h1>
    <button id="login">login</button><button id="logout">logout</button>
    <button id="test">test</button>
    <div id="svg"> </div>
    <div> <img   id="codeImg" src="http://127.0.0.1:7001/user/getcode"> </div>
    <script>
      var token = "" 
      $("#login").click(function(){ 
         $.post("/user/login",{ phone:"008615019469294", password:"30XdRmWtYr6Ug", },function(data){ console.log( data )
          token = data.data.token
        },'json') 
      })
      $("#logout").click(function(){ 
          $.ajax({
                    url: '/user/logout',
                    type: 'POST',
                    dataType: 'json',
                    data: JSON.stringify({ phone:"150194692941",id: 16242 }), 
                    cache: false,
                    headers: { 
                       // "Authorization":`Bearer `+token,
                       "Authorization": token,
                        'Content-Type': 'application/json'//  'application/x-www-form-urlencoded'    //multipart/form-data;boundary=--xxxxxxx   application/json
                    },                
                    success: function(data){
                      console.log( data )  
                    }
          })
      })
      $("#test").click(function(){
        console.log($("#testItem").val())
        var arg = $("#testItem").val();
           // $.post("/user/login",{ phone:"008615019469294", password:"30XdRmWtYr6Ug", },function(data){ console.log( data ) },'json') 
          //  $.get("/user/getcode",{ type:"1", },function(data){
          //     console.log( data )
          //     // $("#svg").html(data.data)
          //      $("#codeImg").src("http://127.0.0.1:7001/user/getcode") 
          //    },'json') 
          // $.post("/user/register",{ phone:"150194692941", password:"30XdRmWtYr6Ug", },function(data){ console.log( data ) },'json') 
          // 不带token 会401
         //$.post("/user/update",{ phone:"150194692941", password:"30XdRmWtYr6Ug", },function(data){ console.log( data ) },'json') 
         // 带了也是非法的token 
         $.ajax({
                    url: '/user/update',
                    type: 'POST',
                    dataType: 'json',
                    data: JSON.stringify({ phone:"150194692941",id: 16242 }), 
                    cache: false,
                    headers: { 
                       // "Authorization":`Bearer `+token,
                       "Authorization": token,
                        'Content-Type': 'application/json'//  'application/x-www-form-urlencoded'    //multipart/form-data;boundary=--xxxxxxx   application/json
                    },                
                    success: function(data){
                      console.log( data )  
                    }
          })
      })
    </script>
    <div class="col c1">
      <h2>测试接口</h2>
      <div id="default-example" data-collapse>
        <h3>列表</h3>
         <div>
           
        </div>
        <h3>详情</h3>
        <div>
            <textarea name="" id="testItem" cols="30" rows="10">
              {
                "page":1
              }
            </textarea> 
            <button id="testItemBtn">test</button>
            <script>
              $("#testItemBtn").click(function(){
                console.log($("#testItem").val())
                var arg = $("#testItem").val();
                $.get("/test/item",{ phone:"008615019469294", password:"30XdRmWtYr6Ug", },function(data){ console.log( data ) },'json') 
              })
            </script>
        </div>
        <h3>上传图片</h3>
        <div>
            <input type="file" name="chooseImg" id="chooseImg"  accept="image/*"   multiple custom-on-change="takePicture"  /> 
            <script>
                $('#chooseImg').change(function(){      upload($('#chooseImg').get(0).files[0]) })
                function upload(file){
                    var formData = new FormData();  formData.append('files', file);  
                    $.ajax({
                      url: "/test/upload",
                      type: "POST",
                      data: formData, 
                      contentType: false, 
                      processData: false,
                      success: function (data) {
                        console.log("data: ",data);   
                      }, 
                    });  
                } 
            </script>
        </div>
      </div>

       
  
      <script>
        new jQueryCollapse($("#custom-show-hide-example"), {
          open: function() {
            this.slideDown(150);
          },
          close: function() {
            this.slideUp(150);
          }
        });
      </script>
      <!-- END Custom open and close -->

      

 

    </div>
  </body>
</html>
